<template>
  <el-dialog  class="fahuodia" title="发货" :close-on-click-modal="false"  :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
      <el-form-item label="订单编号" style="margin-bottom: 8px;width: 400px">
        <el-tag style="margin-left: 0">{{dataForm.orderSn}}</el-tag>
      </el-form-item>
      <el-form-item label="包裹" style="margin-bottom: 0">
        <el-tag style="margin-left: 0" v-for="pack in packages" type="success">{{pack.inTrackingNumber}}</el-tag>
      </el-form-item>
      <el-form-item label="收货地址"  style="margin-bottom: 0">
        国家<el-tag >{{dataForm.country}}</el-tag> 州/省<el-tag>{{dataForm.province}}</el-tag> 城市<el-tag>{{dataForm.city}}</el-tag> 详细地址<el-tag>{{dataForm.address}}</el-tag>
      </el-form-item>
      <el-form-item label="收件人"  style="margin-bottom: 10px">
        <el-tag style="margin-left: 0">{{dataForm.name}}</el-tag> 电话<el-tag>{{dataForm.mobile}}</el-tag> 邮编<el-tag>{{dataForm.zipcode}}</el-tag>
      </el-form-item>
      <el-form-item label="快递公司"  style="margin-bottom: 10px">
        {{dataForm.shippingName}}
      </el-form-item>
      <el-form-item label="快递单号" prop="outTrackingNumber" style="margin-bottom: 8px;width: 400px">
        <el-input v-model="dataForm.outTrackingNumber" placeholder="包裹订单号"></el-input>
      </el-form-item>



    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        packages:[],
        visible: false,
        dataForm: {
          orderId: 0,
          outTrackingNumber:''
        },
        dataRule: {
          outTrackingNumber: [
            { required: true, message: '快递单号不能为空', trigger: 'blur' }
          ]

        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.orderId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.orderId) {
            this.$http({
              url: this.$http.adornUrl(`/order/v9order/info/${this.dataForm.orderId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.shippingName = data.v9Order.shippingName
                this.dataForm.outTrackingNumber = data.v9Order.outTrackingNumber
                this.dataForm.orderSn = data.v9Order.orderSn
                this.dataForm.specialId = data.v9Order.specialId
                this.dataForm.postscript = data.v9Order.postscript
                this.dataForm.addservices = data.v9Order.addservices
                this.dataForm.name = data.v9Order.name
                this.dataForm.country = data.v9Order.country
                this.dataForm.mobile = data.v9Order.mobile
                this.dataForm.city = data.v9Order.city
                this.dataForm.province = data.v9Order.province
                this.dataForm.zipcode = data.v9Order.zipcode
                this.dataForm.address = data.v9Order.address
                this.packages=data.data.packages
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/v9order/fahuo`),
              method: 'post',
              data: this.$http.adornData({
                'orderId': this.dataForm.orderId || undefined,
                'outTrackingNumber': this.dataForm.outTrackingNumber,
                'shippingStatus':1,
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .fahuodia .el-tag{
    margin-right: 5px;
    margin-left: 5px;
  }

</style>
